package com.gylang.pdf.template;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.map.MapBuilder;
import com.gylang.pdf.BaseTemplateTest;
import com.gylang.pdf.PdfTemplateRenderProcessor;
import com.gylang.pdf.SimpleTemplateProcessorTest;
import freemarker.template.TemplateException;
import org.junit.Test;

import java.io.IOException;
import java.util.Map;

/**
 * @author gylang
 * data 2022/1/16
 */
public class 奖状_三好学生 extends BaseTemplateTest {

    public static Map<Object, Object> data() {
        return MapBuilder.create()
                .put("certificate", "三好剑神")
                //                全角空格
                .put("name", "　　李淳罡")
                .put("content", "同学在《剑神修炼班》第999期中学习成绩优异，剑术高超，乐于助人，被评为")
                .put("desc", "特发此状，以资鼓励")
                .put("year", "2099")
                .put("month", "9")
                .build();

    }



    @Test
    public void render() throws IOException, TemplateException {
        PdfTemplateRenderProcessor pdfTemplateRenderProcessor = getPdfTemplateProcessor();
        String file = SimpleTemplateProcessorTest.class.getResource("/template/good_student.html").getFile();
        pdfTemplateRenderProcessor.pushTemplate("good_student", FileUtil.readUtf8String(file));
        String goodStudent = pdfTemplateRenderProcessor.render("good_student", data());
        byte[] bytes = pdfTemplateRenderProcessor.renderByte(goodStudent);
        FileUtil.writeBytes(bytes, System.getProperty("user.dir") + "/render_out/good_student.pdf");
    }
}
